import { GameMap, Zone } from '../types/game';
import { LOOT_TABLES } from './containerConfigs';

// 敌人配置
const ENEMIES = {
  bandit: {
    id: 'bandit',
    name: '流浪匪徒',
    health: 60,
    maxHealth: 60,
    attack: 25,
    defense: 10,
    accuracy: 70,
    lootTable: ['basic_pistol', 'ammo_belt', 'bread'],
    defeated: false
  },
  soldier: {
    id: 'soldier',
    name: '敌方士兵',
    health: 80,
    maxHealth: 80,
    attack: 35,
    defense: 20,
    accuracy: 80,
    lootTable: ['assault_rifle', 'tactical_vest', 'health_potion'],
    defeated: false
  },
  sniper: {
    id: 'sniper',
    name: '狙击手',
    health: 50,
    maxHealth: 50,
    attack: 60,
    defense: 15,
    accuracy: 95,
    lootTable: ['sniper_rifle', 'tactical_helmet', 'strength_potion'],
    defeated: false
  },
  elite: {
    id: 'elite',
    name: '精英战士',
    health: 120,
    maxHealth: 120,
    attack: 45,
    defense: 30,
    accuracy: 85,
    lootTable: ['heavy_armor', 'night_vision_helmet', 'greater_health_potion'],
    defeated: false
  }
};

// 工业区
const INDUSTRIAL_ZONE: Zone = {
  id: 'industrial_zone',
  name: '工业区',
  description: '废弃的工业园区，到处都是破旧的厂房和仓库',
  color: '#8B4513',
  buildings: [
    // 旧工厂
    {
      id: 'old_factory',
      name: '旧工厂',
      description: '一座废弃的制造工厂',
      floors: [
        {
          id: 'factory_floor_1',
          name: '工厂一楼',
          number: 1,
          rooms: [
            {
              id: 'factory_entrance',
              name: '工厂入口',
              description: '工厂的主要入口，大门半开着',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [],
              containers: [
                {
                  id: 'entrance_locker',
                  typeId: 'locker',
                  searched: false
                }
              ]
            },
            {
              id: 'assembly_line',
              name: '装配线',
              description: '废弃的装配线，到处是生锈的机械',
              hasLoot: true,
              lootTableId: 'factory_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.bandit }],
              containers: [
                {
                  id: 'worker_toolbox',
                  typeId: 'toolbox',
                  searched: false
                },
                {
                  id: 'parts_container',
                  typeId: 'plastic_container',
                  searched: false
                }
              ]
            },
            {
              id: 'storage_room',
              name: '储物间',
              description: '堆满了废料的储物间',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [],
              containers: [
                {
                  id: 'storage_small_safe',
                  typeId: 'small_safe',
                  searched: false,
                  locked: true,
                  requiredKey: 'rusty_key'
                },
                {
                  id: 'supply_delivery_box',
                  typeId: 'delivery_box',
                  searched: false
                }
              ]
            }
          ]
        },
        {
          id: 'factory_floor_2',
          name: '工厂二楼',
          number: 2,
          rooms: [
            {
              id: 'office_area',
              name: '办公区',
              description: '废弃的办公区域，桌椅散乱',
              hasLoot: true,
              lootTableId: 'office_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.soldier }],
              containers: [
                {
                  id: 'office_locker_1',
                  typeId: 'locker',
                  searched: false
                },
                {
                  id: 'office_locker_2',
                  typeId: 'locker',
                  searched: false
                },
                {
                  id: 'first_aid_cabinet',
                  typeId: 'medical_cabinet',
                  searched: false
                }
              ]
            },
            {
              id: 'manager_office',
              name: '经理办公室',
              description: '豪华的经理办公室，保险柜还在',
              hasLoot: false, // 经理办公室主要靠保险柜
              searched: false,
              enemies: [{ ...ENEMIES.sniper }],
              containers: [
                {
                  id: 'manager_large_safe',
                  typeId: 'large_safe',
                  searched: false,
                  locked: true,
                  requiredKey: 'golden_key'
                },
                {
                  id: 'manager_desk_drawer',
                  typeId: 'plastic_container',
                  name: '办公桌抽屉',
                  searched: false
                }
              ]
            }
          ]
        }
      ]
    },
    // 仓库区
    {
      id: 'warehouse_complex',
      name: '仓库区',
      description: '大型货物仓储区域',
      floors: [
        {
          id: 'warehouse_floor_1',
          name: '仓库一楼',
          number: 1,
          rooms: [
            {
              id: 'loading_dock',
              name: '装卸区',
              description: '货物装卸平台，有几辆废弃卡车',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.bandit }, { ...ENEMIES.soldier }],
              containers: [
                {
                  id: 'truck_cargo_container',
                  typeId: 'delivery_box',
                  name: '卡车货箱',
                  searched: false
                },
                {
                  id: 'dock_toolbox',
                  typeId: 'toolbox',
                  searched: false
                }
              ]
            },
            {
              id: 'storage_hall',
              name: '储存大厅',
              description: '巨大的储存空间，货架林立',
              hasLoot: true,
              lootTableId: 'factory_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.elite }],
              containers: [
                {
                  id: 'weapons_cache',
                  typeId: 'weapon_cache',
                  searched: false,
                  locked: true,
                  requiredKey: 'golden_key'
                },
                {
                  id: 'supplies_container_1',
                  typeId: 'delivery_box',
                  name: '补给箱A',
                  searched: false
                },
                {
                  id: 'supplies_container_2',
                  typeId: 'delivery_box',
                  name: '补给箱B',
                  searched: false
                }
              ]
            },
            {
              id: 'zone_transition_to_residential',
              name: '通往住宅区',
              description: '通向住宅区的安全通道，可以快速移动到住宅区',
              hasLoot: false,
              lootTable: [],
              searched: false,
              enemies: [],
              isZoneTransition: true,
              connectedZone: 'residential_zone'
            }
          ]
        }
      ]
    }
  ]
};

// 住宅区
const RESIDENTIAL_ZONE: Zone = {
  id: 'residential_zone',
  name: '住宅区',
  description: '废弃的居民住宅区，房屋密集但大多已无人居住',
  color: '#4682B4',
  buildings: [
    // 公寓楼
    {
      id: 'apartment_building',
      name: '公寓楼',
      description: '五层高的居民楼',
      floors: [
        {
          id: 'apartment_floor_1',
          name: '公寓一楼',
          number: 1,
          rooms: [
            {
              id: 'lobby',
              name: '大厅',
              description: '公寓大厅，信箱散落一地',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [],
              containers: [
                {
                  id: 'mailbox_container',
                  typeId: 'plastic_container',
                  name: '信箱',
                  searched: false
                }
              ]
            },
            {
              id: 'apartment_101',
              name: '101室',
              description: '一室一厅的小公寓',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.bandit }],
              containers: [
                {
                  id: 'bedroom_safe',
                  typeId: 'small_safe',
                  searched: false
                },
                {
                  id: 'kitchen_cabinet',
                  typeId: 'plastic_container',
                  name: '厨房橱柜',
                  searched: false
                }
              ]
            },
            {
              id: 'zone_transition_to_industrial',
              name: '通往工业区',
              description: '通向工业区的地下通道',
              hasLoot: false,
              lootTable: [],
              searched: false,
              enemies: [],
              isZoneTransition: true,
              connectedZone: 'industrial_zone'
            },
            {
              id: 'zone_transition_to_commercial',
              name: '通往商业区',
              description: '通向商业区的街道',
              hasLoot: false,
              lootTable: [],
              searched: false,
              enemies: [],
              isZoneTransition: true,
              connectedZone: 'commercial_zone'
            }
          ]
        },
        {
          id: 'apartment_floor_2',
          name: '公寓二楼',
          number: 2,
          rooms: [
            {
              id: 'apartment_201',
              name: '201室',
              description: '较大的两室公寓',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.soldier }, { ...ENEMIES.bandit }],
              containers: [
                {
                  id: 'living_room_cabinet',
                  typeId: 'locker',
                  name: '客厅柜子',
                  searched: false
                },
                {
                  id: 'bathroom_medicine_cabinet',
                  typeId: 'medical_cabinet',
                  name: '浴室药柜',
                  searched: false
                }
              ]
            },
            {
              id: 'apartment_202',
              name: '202室',
              description: '豪华公寓，装修精美',
              hasLoot: false, // 豪华公寓主要靠保险柜
              searched: false,
              enemies: [{ ...ENEMIES.elite }],
              containers: [
                {
                  id: 'luxury_large_safe',
                  typeId: 'large_safe',
                  searched: false
                },
                {
                  id: 'luxury_medicine_cabinet',
                  typeId: 'medical_cabinet',
                  name: '高级药柜',
                  searched: false
                },
                {
                  id: 'wine_cabinet',
                  typeId: 'locker',
                  name: '酒柜',
                  searched: false
                }
              ]
            }
          ]
        },
        {
          id: 'apartment_floor_5',
          name: '公寓五楼（天台）',
          number: 5,
          rooms: [
            {
              id: 'rooftop',
              name: '天台',
              description: '楼顶天台，视野开阔',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.sniper }],
              containers: [
                {
                  id: 'rooftop_equipment_box',
                  typeId: 'toolbox',
                  name: '天台设备箱',
                  searched: false
                }
              ]
            },
            {
              id: 'extraction_point_2',
              name: '撤离点B',
              description: '天台撤离点，绳索垂降设备',
              hasLoot: false,
              lootTable: [],
              searched: false,
              enemies: [],
              isExtractionPoint: true
            }
          ]
        }
      ]
    }
  ]
};

// 商业区
const COMMERCIAL_ZONE: Zone = {
  id: 'commercial_zone',
  name: '商业区',
  description: '废弃的商业中心，商店和办公楼林立',
  color: '#DAA520',
  buildings: [
    // 购物中心
    {
      id: 'shopping_mall',
      name: '购物中心',
      description: '大型购物中心，内部结构复杂',
      floors: [
        {
          id: 'mall_floor_1',
          name: '商场一楼',
          number: 1,
          rooms: [
            {
              id: 'main_entrance',
              name: '主入口',
              description: '商场的主要入口大厅',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [],
              containers: [
                {
                  id: 'info_desk_drawer',
                  typeId: 'plastic_container',
                  name: '服务台抽屉',
                  searched: false
                }
              ]
            },
            {
              id: 'electronics_store',
              name: '电子商店',
              description: '废弃的电子产品商店',
              hasLoot: true,
              lootTableId: 'abandoned_area_loot',
              searched: false,
              enemies: [{ ...ENEMIES.bandit }, { ...ENEMIES.soldier }],
              containers: [
                {
                  id: 'electronics_safe',
                  typeId: 'small_safe',
                  searched: false,
                  locked: true,
                  requiredKey: 'golden_key'
                },
                {
                  id: 'display_cabinet',
                  typeId: 'locker',
                  name: '展示柜',
                  searched: false
                }
              ]
            },
            {
              id: 'weapon_shop',
              name: '军品店',
              description: '专门销售军用装备的商店',
              hasLoot: false, // 军品店主要靠武器储藏箱
              searched: false,
              enemies: [{ ...ENEMIES.elite }],
              containers: [
                {
                  id: 'shop_weapons_cache',
                  typeId: 'weapon_cache',
                  searched: false
                },
                {
                  id: 'shop_armor_locker',
                  typeId: 'locker',
                  name: '护甲柜',
                  searched: false
                },
                {
                  id: 'shop_register_safe',
                  typeId: 'small_safe',
                  name: '收银机保险柜',
                  searched: false
                }
              ]
            },
            {
              id: 'zone_transition_to_residential',
              name: '通往住宅区',
              description: '连接住宅区的天桥',
              hasLoot: false,
              lootTable: [],
              searched: false,
              enemies: [],
              isZoneTransition: true,
              connectedZone: 'residential_zone'
            },
            {
              id: 'extraction_point_3',
              name: '撤离点C',
              description: '商场后门撤离区域',
              hasLoot: false,
              lootTable: [],
              searched: false,
              enemies: [],
              isExtractionPoint: true
            }
          ]
        }
      ]
    }
  ]
};

// 主游戏地图 - 城市废墟
export const CITY_RUINS_MAP: GameMap = {
  id: 'city_ruins',
  name: '城市废墟',
  description: '一座被战火摧毁的城市，分为工业区、住宅区和商业区三个主要区域',
  zones: [INDUSTRIAL_ZONE, RESIDENTIAL_ZONE, COMMERCIAL_ZONE],
  startingZone: 'industrial_zone'
};

// 行动配置
export const ACTIONS = {
  MOVE: {
    type: 'move' as const,
    timeCost: 60, // 1分钟
    description: '移动到其他房间'
  },
  ZONE_TRAVEL: {
    type: 'zone_travel' as const,
    timeCost: 300, // 5分钟 - 区域间移动需要更多时间
    description: '移动到其他区域'
  },
  SEARCH: {
    type: 'search' as const,
    timeCost: 180, // 3分钟
    description: '搜索当前房间'
  },
  ATTACK: {
    type: 'attack' as const,
    timeCost: 120, // 2分钟
    description: '攻击敌人'
  },
  HEAL: {
    type: 'heal' as const,
    timeCost: 90, // 1.5分钟
    description: '使用药品治疗'
  },
  REST: {
    type: 'rest' as const,
    timeCost: 300, // 5分钟
    description: '休息恢复体力'
  },
  EXTRACT: {
    type: 'extract' as const,
    timeCost: 30, // 30秒
    description: '撤离离开'
  }
};

// 导出主地图（保持向后兼容）
export const ALL_LOCATIONS = {
  city_ruins: CITY_RUINS_MAP
};

// 导出战利品表供其他模块使用
export { LOOT_TABLES } from './containerConfigs';